From 8f8a15614f0dfddc349c101ce4f5d4edb5133815 Mon Sep 17 00:00:00 2001
From: James Le Cuirot <james.le-cuirot@yakara.com>
Date: Tue, 17 May 2016 12:05:29 +0100
Subject: [PATCH] Add --http option for connecting over HTTP

This allows the use of HTTP proxies.
---
 sendxmpp | 19 +++++++++++++------
 1 file changed, 13 insertions(+), 6 deletions(-)

diff --git a/sendxmpp b/sendxmpp
index fafb0a5..8a9758e 100755
--- a/sendxmpp
+++ b/sendxmpp
@@ -28,7 +28,7 @@ use open ':utf8';
 use open ':std';
 
 # subroutines decls
-sub xmpp_login($$$$$$$$$$$$);
+sub xmpp_login($$$$$$$$$$$$$);
 sub xmpp_send ($$$$);
 sub xmpp_send_raw_xml($$);
 sub xmpp_send_message($$$$$$);
@@ -82,6 +82,7 @@ sub main () { # {{{
 		$$cmdline{'no-tls-verify'} || $$config{'no-tls-verify'},
 		$$cmdline{'tls-ca-path'} || $$config{'tls-ca-path'} || '',
 		$$cmdline{'ssl'},
+		$$cmdline{'http'} || $$config{'http'} || 0,
 		$$cmdline{'debug'},
 		$$cmdline{'sso'}
 	) or error_exit("cannot login: $!");
@@ -211,7 +212,7 @@ sub parse_cmdline () { # {{{
 
 	my ($subject, $file, $resource, $jserver, $port, $username, $password, $sso, $component, 
 		$message, $chatroom, $headline, $debug, $tls, $ssl,
-		$no_tls_verify, $tls_ca_path,
+		$no_tls_verify, $tls_ca_path, $http,
 		$interactive, $help, $raw, $verbose
 	);
     $debug = 0;
@@ -232,6 +233,7 @@ sub parse_cmdline () { # {{{
 		'no-tls-verify|n'	=> \$no_tls_verify,
 		'tls-ca-path|a=s'	=> \$tls_ca_path,
 		'ssl|e'				=> \$ssl,
+		'http'				=> \$http,
 		'interactive|i'		=> \$interactive,
 		'help|usage|h'		=> \$help,
 		'debug|d:i'			=> sub { $debug = $_[1] ? $_[1] : $debug + 1 },
@@ -301,6 +303,7 @@ sub parse_cmdline () { # {{{
 		'no-tls-verify'	=> ($no_tls_verify or 0),
 		'tls-ca-path'	=> ($tls_ca_path or ''),
 		'ssl'			=> ($ssl or 0),
+		'http'			=> ($http or 0),
 		'debug'			=> ($debug or 0),
 		'verbose'		=> ($verbose or 0),
 		'raw'			=> ($raw or 0),
@@ -319,12 +322,12 @@ sub parse_cmdline () { # {{{
 
 #
 # xmpp_login: login to the xmpp (jabber) server
-# input: hostname, port, username, password, resource, tls, ssl, debug
+# input: hostname, port, username, password, resource, tls, ssl, http, debug
 # output: an XMPP connection object
 #
-sub xmpp_login ($$$$$$$$$$$$) { # {{{
+sub xmpp_login ($$$$$$$$$$$$$) { # {{{
 
-    my ($host, $port, $user, $pw, $comp, $res, $tls, $no_tls_verify, $tls_ca_path, $ssl, $debug, $sso) = @_;
+    my ($host, $port, $user, $pw, $comp, $res, $tls, $no_tls_verify, $tls_ca_path, $ssl, $http, $debug, $sso) = @_;
     my $cnx = new Net::XMPP::Client(debuglevel=>$debug);
     error_exit "could not create XMPP client object: $!"
 	unless ($cnx);
@@ -343,7 +346,7 @@ sub xmpp_login ($$$$$$$$$$$$) { # {{{
 		ssl_verify		=> $ssl_verify,
 		ssl_ca_path		=> $tls_ca_path,
 		ssl             => $ssl,
-		connectiontype	=> 'tcpip',
+		connectiontype	=> $http ? 'http' : 'tcpip',
 		componentname	=> $comp,
 		srv				=> 1, # enable SRV lookups
 	};
@@ -641,6 +644,10 @@ Deactivate the verification of SSL certificates. Better way is to use parameter
 
 Path to your custom CA certificates, so you can verificate SSL certificates during connecting.
 
+=item B<--http>
+
+Connect over HTTP, allowing the use of a proxy.
+
 =item B<-l>, B<--headline>
 
 Backward compatibility option. You should use B<--message-type=headline> instead. Send a headline type message (not stored in offline messages)
